package jjn.round2;

import commons.TreeNode;

/**
 * @author Jiang Jining
 * @since 2023-05-03 14:26
 */
public class Offer28_SymmetricTree {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return isSymmetricTree(root.left, root.right);
    }
    
    private boolean isSymmetricTree(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        return left.val == right.val && isSymmetricTree(left.left, right.right)
                && isSymmetricTree(left.right, right.left);
    }
}
